function CommonChart(chartDiv,title,yAxisName,dataMap){
	this.chartDiv = chartDiv;
	this.title = title;
	this.yAxisName = yAxisName;
	this.dataMap = dataMap;
	this.chartString = "";
	this.chartTypeArray = ["MSLine","ScrollCombi2D","ScrollCombiDY2D","Column2D"];
	this.chartType=this.chartTypeArray[0];
	this.width="727";
	this.height="325";
};

CommonChart.prototype.selectChartType=function(selectIndex){
	this.chartType=this.chartTypeArray[selectIndex];
};

CommonChart.prototype.setChartType=function(charttype){
	this.chartType=charttype;
};

CommonChart.prototype.setChartRectangle=function(width,height){
	this.width=width;
	this.height=height;
};

CommonChart.prototype.generateDataString = function(getCategoryMap,getSeriesMap,getValueKey){
	categoryMap =getCategoryMap();
	seriesMap =getSeriesMap();
	var numVDivLines = categoryMap.size();
	if(numVDivLines<=0){
		categoryMap.put("","");
	}
	if(numVDivLines<8){
		numVDivLines = 8;
	}
	if(numVDivLines>20){
		numVDivLines = 20;
	}
	this.chartString ="<chart caption='"+ this.title+"' baseFontSize='12' palette='3' YAxisName='"+ this.yAxisName+"' numdivlines='8' lineThickness='2' showValues='0' anchorRadius='3' anchorBgAlpha='50' numVDivLines='"+numVDivLines+"' showAlternateVGridColor='1' alternateVGridAlpha='3' formatNumber='0' formatNumberScale='0' animation='1' numVisiblePlot='12'>";
	this.chartString+="<categories >";
	for(var i in categoryMap.keys()){
		var key2 = categoryMap.keys()[i];
		var categoryName =categoryMap.get(key2);
			if(categoryName === undefined){
				categoryName="";
		}
		this.chartString+="<category label='"+categoryName+"' />";
	}
	this.chartString+="</categories>";
	
	var seriesLenght = seriesMap.size();
	var showSeries = true;
	if(seriesLenght<=0){
		seriesMap.put("","");
	}
	if(seriesLenght<=0){
		showSeries = false;
	}
	for(var j in seriesMap.keys()){
		var key1 = seriesMap.keys()[j];
		this.chartString+="<dataset ";
		if(showSeries){
			var seriesName =seriesMap.get(key1);
			if(seriesName === undefined){
				seriesName="";
			}
			this.chartString+="seriesName='"+seriesName+"'";
		}
		this.chartString+=">";
		for(var k in categoryMap.keys()){
			var key2 = categoryMap.keys()[k];
			var vkey = getValueKey(key1,key2);
			var value = 0;
			try{ 
				value =this.dataMap[vkey];
				if (value == undefined){
					value =0;
				}
			} catch   (e) {
				value = 0;
			}
    		this.chartString+='<set value="'+value+'"/>';
		}
		this.chartString+="</dataset>";
	}
	this.chartString+="</chart>";
};

CommonChart.prototype.draw = function(getCategoryMap,getSeriesMap,getValueKey){
	this.generateDataString(getCategoryMap,getSeriesMap,getValueKey);
	var chart = new FusionCharts("../static/FusionCharts/"+this.chartType+".swf", "CommonChart_"+this.chartDiv, this.width, this.height, "0", "0");
    chart.setXMLData(this.chartString);
    chart.render(this.chartDiv);
};